package com.app.commons.utils;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {
    /**
     * 创建分页对象
     * @param pageIndex 页码
     * @param pageSize 页大小
     * @param totalCount 总数据数
     * @param list 集合数据
     */
    public Page(int pageIndex, int pageSize, int totalCount, List<T> list) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.list = list;
        //计算总页数
        if(this.totalCount%this.pageSize==0){
            this.pageCount=this.totalCount/this.pageSize;
        }else{
            this.pageCount=this.totalCount/this.pageSize+1;
        }
    }
    private int pageIndex;      //页码
    private int pageSize;       //页大小
    private int pageCount;      //页数
    private int totalCount;     //数据数
    private List<T> list;       //某一页的数据
    private boolean hasPrevious; //是否有上一页
    private boolean hasNext;     //是否有下一页

    public List<T> getList() {
        return list;
    }
    public void setList(List<T> list) {
        this.list = list;
    }
    public boolean isHasPrevious() {
        return this.pageIndex > 1;
    }
    public boolean isHasNext() {
        return this.pageIndex < this.pageCount;
    }
    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getPageCount() {
        return pageCount;
    }

    public int getTotalCount() {
        return totalCount;
    }

}
